﻿package com.wandian.view.components.ui.mingame.sgj
{
	import com.wandian.ApplicationFacade;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.model.vo.PropVo;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZLlistScrollPanel;
	import com.wandian.util.CLZLoadIcon;
	import com.wandian.util.CLZTabBar;
	import com.wandian.util.CLZZoom;
	import com.wandian.util.GlowFilterManage;
	import com.wandian.util.ToolTip;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	dynamic public class MaxWinGame extends MovieClip
	{
		private var facade:ApplicationFacade;
		private var _arrMc:Array;
		private var _nLen:int;
		private var nMcNum:int=0;
		private var INIT_START_TIME:int=200;
		private var INIT_OVER_TIME:int=300;
		private var _nOverTimer:int;
		private var INIT_NUM:int=7;
		private var _nCurrentNum:int=0;
		private var _nCurrentTimer:int=0;
		private var _isStartOver:Boolean=false;
		private var timer:Timer;
		private var _nSelectNum:int=5;
		private var _arrResult:Array;
		private var _mcPanel:MovieClip;
		private var _global:GameData;

		public function MaxWinGame(param1:MovieClip):void
		{
			this.facade=ApplicationFacade.getInstance();
			this._global=GameData.getInstance();
			this._arrMc=[param1.f0, param1.f1, param1.f2, param1.f3, param1.f4, param1.f5, param1.f6, param1.f7, param1.f8, param1.f9, param1.f10, param1.f11, param1.f12, param1.f13, param1.f14, param1.f15];
			this._nLen=this._arrMc.length;
			this._mcPanel=param1;
			this._mcPanel.btn.addEventListener(MouseEvent.CLICK, this.clickHd);
			this.init();
			return;
		} 

		public function startGame(param1:Array):void
		{
			this._arrResult=param1;
			this._global.userInfo.money=this._global.userInfo.userVo.money - 388;
			this._nSelectNum=this._arrResult[4] - 1;
			this.init();
			this.initTimer();
			return;
		} 

		private function init():void
		{
			var _loc_1:int=0;
			while (_loc_1 < this._nLen)
			{

				this._arrMc[_loc_1].gotoAndStop(1);
				_loc_1=_loc_1 + 1;
			}
			this._nCurrentTimer=0;
			this._isStartOver=false;
			this._nCurrentTimer=this.INIT_START_TIME;
			this._nCurrentNum=0;
			return;
		} 

		private function fun():void
		{
			this.nMcNum++;
			if (this.nMcNum >= this._nLen)
			{
				this.nMcNum=0;
				this.nMcNum++;
			}
			this._arrMc[this.nMcNum].gotoAndPlay(2);
			return;
		} 

		private function timerCompleteHandler(event:TimerEvent):void
		{
			var _loc_2:String=null;
			var _loc_3:PropVo=null;
			this.fun();
			if (this._nCurrentTimer <= 10)
			{
				if (this.INIT_NUM - this._nCurrentNum > 2)
				{
					this._nCurrentTimer=10;
				}
				else
				{
					this._nCurrentTimer=this._nCurrentTimer + 10;
				}
			}
			else if (this.INIT_NUM - this._nCurrentNum > 2)
			{
				this._nCurrentTimer=this._nCurrentTimer - 10;
			}
			else
			{
				if (this._isStartOver)
				{
				}
				if (this.nMcNum == this._nSelectNum)
				{
					this._mcPanel.btn.mouseEnabled=true;
					this._mcPanel.btn.alpha=1;
					this.removeTimer();
					this._arrMc[this.nMcNum].gotoAndStop(2);
					_loc_2="";
					if (this._arrResult[0])
					{
						if (this._arrResult[1] == 1)
						{
							_loc_2=_loc_2 + GameData.replaceStrValue(GameData.tip["GET_SGJ_PRIZE_GOLD"], "NUM", this._arrResult[3]);
							this._global.userInfo.money=this._arrResult[2];
						}
						else
						{
							_loc_3=GameData.getPropById(this._arrResult[2], this._arrResult[3]);
							_loc_2=_loc_2 + GameData.replaceStrValue(GameData.tip["GET_SGJ_PRIZE_PROP"], "NAME", _loc_3.name + " X 1");
						}
					}
					this.facade.sendNotification(CLZNoticeName.SHOW_MOVE_TIP, {tip: _loc_2});
					return;
				}
				if (this.nMcNum != this._nSelectNum)
				{
				}
				if (this._isStartOver)
				{
					if (!this._isStartOver)
					{
						this._isStartOver=true;
						this._nOverTimer=this.INIT_OVER_TIME / this._nLen;
						this._nCurrentTimer=this._nCurrentTimer + this._nOverTimer;
					}
					else
					{
						this._nCurrentTimer=this._nCurrentTimer + this._nOverTimer;
					}
				}
			}
			this.initTimer();
			return;
		} 

		private function initTimer():void
		{
			this.removeTimer();
			this.timer=new Timer(this._nCurrentTimer, 1);
			this.timer.addEventListener(TimerEvent.TIMER_COMPLETE, this.timerCompleteHandler);
			this.timer.start();
			return;
		} 

		private function removeTimer():void
		{
			if (this.timer != null)
			{
				this.timer.reset();
				this.timer.removeEventListener(TimerEvent.TIMER_COMPLETE, this.timerCompleteHandler);
				this.timer=null;
			}
			return;
		} 

		private function clickHd(event:MouseEvent):void
		{
			if (this._global.userInfo.userVo.money < int(GameData.config["SGJ_GOLD"]))
			{
				this.facade.sendNotification(CLZNoticeName.SHOW_MOVE_TIP, {tip: GameData.tip["GAME_GOLD_NOT_ENOUGH"]});
				return;
			}
			this._mcPanel.btn.mouseEnabled=false;
			this._mcPanel.btn.alpha=0.5;
			this.facade.sendNotification(CLZNoticeName.SGJ_ZP_REQ, 1);
			return;
		} 

	}
}
